package com.aspose.cells;

import java.util.Iterator;

class zadx {
   private Workbook a;
   private int b = 0;
   private int c = 0;
   private Worksheet d = null;
   private zaeb e = null;
   private boolean f = false;
   private zaeh g = null;

   zadx(zaeh var1, String var2, HtmlSaveOptions var3) {
      this.g = var1;
      this.a = this.g.g;
      int var4 = this.g.r.size();
      if (var4 == 1) {
         this.d = (Worksheet)this.g.r.get(0);
         this.e = new zaeb(var1, -1, var2, var3);
      } else if (var4 == 0) {
         this.f = true;
      }

      int var5 = this.a.getWorksheets().getActiveSheetIndex();

      for(int var6 = 0; var6 < var4; ++var6) {
         Worksheet var7 = (Worksheet)this.g.r.get(var6);
         if (var7.isVisible()) {
            ++this.c;
         }

         if (var7.getIndex() == var5) {
            this.b = var6;
         }
      }

   }

   void a(zafg var1, String var2, String var3, String var4, String var5, HtmlSaveOptions var6) throws Exception {
      zafg var7 = this.g.a(var1, var2, var3, var4, var5);

      try {
         if (this.f) {
            this.a(var7);
            return;
         }

         zady var11;
         if (!this.g.a() && var6.getExportDataOptions() == 1) {
            this.e.b(var7, var2, var3, var4, var5, var6);
            String var16 = "stylesheet.css";
            StreamProviderOptions var17 = new StreamProviderOptions();
            zafg var18 = this.g.b(var1, var2, var16, var4, var5, var17);
            var18.b("table");
            var18.b(" {mso-displayed-decimal-separator:\"\\.\";");
            var18.b(" mso-displayed-thousand-separator:\"\\,\";}");
            this.e.b(var18);
            var18.g();
            var11 = new zady(this.g);
            var11.a(var18);
            this.g.u.closeStream(var17);
            return;
         }

         boolean var8 = 1 == this.a.getWorksheets().getCount() && this.a.getWorksheets().get(0).getDisplayRightToLeft();
         var7.a("<!doctype html public \"-//w3c//dtd xhtml 1.0 transitional//en\" \"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd\">");
         var7.g();
         var7.a(true, var8);
         var7.g();
         var7.d();
         var7.a(this.g.a());
         this.d(var7);
         this.b(var7);
         this.e(var7);
         if (this.g.a()) {
            this.f(var7);
         } else {
            this.c(var7);
         }

         int var9 = this.g.g.getWorksheets().B().getCount();
         this.g(var7);
         var7.e();
         if (this.g.a()) {
            this.i(var7);
         } else {
            this.e.b(var7, var2, var3, var4, var5, var6);
         }

         int var10 = this.g.g.getWorksheets().B().getCount();
         if (var10 != var9) {
            var7.b("<style>");
            var7.b("<!--");
            var11 = new zady(this.g);
            int var12 = var9;

            while(true) {
               if (var12 >= var10) {
                  var7.b("-->");
                  var7.b("</style>");
                  break;
               }

               var11.a(var7, this.g.g.getWorksheets().B().a(var12), var12);
               ++var12;
            }
         }

         var7.c();
         var7.g();
         var7.h();
      } finally {
         if (!this.g.b() && var7 != null && var1 == null) {
            var7.f();
         }

      }

   }

   private void a(zafg var1) throws Exception {
      var1.a("<!doctype html public \"-//w3c//dtd xhtml 1.0 transitional//en\" \"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd\">");
      var1.g();
      var1.a(true, false);
      var1.g();
      var1.d();
      var1.a(false);
      this.b(var1);
      this.e(var1);
      var1.e();
      var1.b("<body link=blue vlink=purple>");
      var1.b("no sheets for display");
      var1.b("</body>");
      var1.c();
      var1.g();
      var1.f();
   }

   private void b(zafg var1) throws Exception {
      if (this.g.l != null && this.g.l.length() != 0) {
         String var2 = "<title>" + this.g.l + "</title>";
         var1.b(var2);
      }
   }

   private void c(zafg var1) throws Exception {
      var1.b("<style>");
      var1.b("<!--table");
      var1.b(" {mso-displayed-decimal-separator:\"\\.\";");
      var1.b(" mso-displayed-thousand-separator:\"\\,\";}");
      this.e.b(var1);
      var1.g();
      zady var2 = new zady(this.g);
      var2.a(var1);
      var1.b("-->");
      var1.b("</style>");
   }

   private void d(zafg var1) throws Exception {
      String var2 = (String)this.g.v.get("filelist.xml");
      if (var2 != null) {
         var1.b("<link rel=File-List href=\"" + var2 + "\">");
      } else {
         var1.b("<link rel=File-List href=\"" + this.g.o + "/filelist.xml\">");
      }

      var1.b("<link rel=Edit-Time-Data href=\"" + this.g.o + "/editdata.mso\">");
      var1.b("<link rel=OLE-Object-Data href=\"" + this.g.o + "/oledata.mso\">");
   }

   private void e(zafg var1) throws Exception {
      var1.b("<!--[if gte mso 9]><xml>");
      var1.b(" <o:DocumentProperties>");
      BuiltInDocumentPropertyCollection var2 = this.g.g.getWorksheets().getBuiltInDocumentProperties();
      String var3 = var2.getTitle();
      if (var3.length() > 0) {
         var1.b("  <o:Title>" + zaff.a(var3) + "</o:Title>");
      }

      var3 = var2.getSubject();
      if (var3.length() > 0) {
         var1.b("  <o:Subject>" + zaff.a(var3) + "</o:Subject>");
      }

      var3 = var2.getAuthor();
      if (var3.length() > 0) {
         var1.b("  <o:Author>" + zaff.a(var3) + "</o:Author>");
      }

      var3 = var2.getKeywords();
      if (var3.length() > 0) {
         var1.b("  <o:Keywords>" + zaff.a(var3) + "</o:Keywords>");
      }

      int var4 = var2.getRevisionNumber();
      if (var4 > 0) {
         var1.b("  <o:Revision>" + zase.y(var4) + "</o:Revision>");
      }

      double var5 = var2.getTotalEditingTime();
      if (var5 > 0.0D) {
         var1.b("  <o:TotalTime>" + zase.b(var5) + "</o:TotalTime>");
      }

      DateTime var7 = var2.getLastPrinted();
      if (com.aspose.cells.a.c.zk.b(var7, DateTime.a)) {
         var3 = var7.a("yyyy-MM-dd\\THH:mm:ss\\Z", com.aspose.cells.b.a.c.za.b());
         var1.b("  <o:LastPrinted>" + var3 + "</o:LastPrinted>");
      }

      var7 = var2.getCreatedTime();
      if (com.aspose.cells.a.c.zk.b(var7, DateTime.a)) {
         var3 = var7.a("yyyy-MM-dd\\THH:mm:ss\\Z", com.aspose.cells.b.a.c.za.b());
         var1.b("  <o:Created>" + var3 + "</o:Created>");
      }

      var7 = var2.getLastSavedTime();
      if (com.aspose.cells.a.c.zk.b(var7, DateTime.a)) {
         var3 = var7.a("yyyy-MM-dd\\THH:mm:ss\\Z", com.aspose.cells.b.a.c.za.b());
         var1.b("  <o:LastSaved>" + var3 + "</o:LastSaved>");
      }

      var4 = var2.getPages();
      if (var4 > 0) {
         var1.b("  <o:Pages>" + zase.y(var4) + "</o:Pages>");
      }

      var4 = var2.getWords();
      if (var4 > 0) {
         var1.b("  <o:Words>" + zase.y(var4) + "</o:Words>");
      }

      var4 = var2.getCharacters();
      if (var4 > 0) {
         var1.b("  <o:Characters>" + zase.y(var4) + "</o:Characters>");
      }

      var3 = var2.getCategory();
      if (var3.length() > 0) {
         var1.b("  <o:Category>" + var3 + "</o:Category>");
      }

      var3 = var2.getManager();
      if (var3.length() > 0) {
         var1.b("  <o:Manager>" + zaff.a(var3) + "</o:Manager>");
      }

      var3 = var2.getCompany();
      if (var3.length() > 0) {
         var1.b("  <o:Company>" + zaff.a(var3) + "</o:Company>");
      }

      var4 = var2.getBytes();
      if (var4 > 0) {
         var1.b("  <o:Bytes>" + zase.y(var4) + "</o:Bytes>");
      }

      var4 = var2.getLines();
      if (var4 > 0) {
         var1.b("  <o:Lines>" + zase.y(var4) + "</o:Lines>");
      }

      var4 = var2.getParagraphs();
      if (var4 > 0) {
         var1.b("  <o:Paragraphs>" + zase.y(var4) + "</o:Paragraphs>");
      }

      var4 = var2.getCharactersWithSpaces();
      if (var4 > 0) {
         var1.b("  <o:CharactersWithSpaces>" + zase.y(var4) + "</o:CharactersWithSpaces>");
      }

      var1.b("</o:DocumentProperties>");
      var1.b("</xml><![endif]-->");
   }

   private void f(zafg var1) throws Exception {
      var1.b("<![if !supportTabStrip]>");

      int var2;
      for(var2 = 1; var2 <= this.c; ++var2) {
         String var3 = (String)this.g.v.get("sheet" + zaff.a(var2, 3) + ".htm");
         if (var3 != null) {
            var1.b("<link id=\"shLink\" href=\"" + var3 + "\">");
         } else {
            var1.b("<link id=\"shLink\" href=\"" + this.g.o + "/sheet" + zaff.a(var2, 3) + ".htm\">");
         }
      }

      var1.g();
      var1.b("<link id=\"shLink\">");
      var1.g();
      var1.b("<script language=\"JavaScript\">");
      var1.b("<!--");
      var1.b(" var c_lTabs=" + zase.y(this.c) + ";");
      var1.g();
      var1.b(" var c_rgszSh=new Array(c_lTabs);");

      for(var2 = 0; var2 < this.g.r.size(); ++var2) {
         Worksheet var4 = (Worksheet)this.g.r.get(var2);
         if (!var4.isVisible()) {
            break;
         }

         var1.b(" c_rgszSh[" + zase.y(var2) + "]=\"" + zaff.c(var4.getName()) + "\";");
      }

      var1.g();
      var1.g();
      var1.g();
      zadv.a(var1, this.b);
      var1.b("</script>");
      var1.b("<![endif]>");
   }

   private void g(zafg var1) throws Exception {
      var1.b("<!--[if gte mso 9]><xml>");
      var1.b(" <x:ExcelWorkbook>");
      var1.b("  <x:ExcelWorksheets>");
      if (this.g.a()) {
         for(int var2 = 0; var2 < this.g.r.size(); ++var2) {
            Worksheet var3 = (Worksheet)this.g.r.get(var2);
            this.a(var1, var3, var2 + 1);
         }
      } else {
         var1.b("   <x:ExcelWorksheet>");
         var1.b("    <x:Name>" + this.a(this.d.getName()) + "</x:Name>");
         this.e.c(var1);
         this.e.a(var1);
         var1.b("   </x:ExcelWorksheet>");
      }

      var1.b("  </x:ExcelWorksheets>");
      if (this.g.a()) {
         String var4 = (String)this.g.v.get("stylesheet.css");
         if (var4 != null) {
            var1.b("  <x:Stylesheet HRef=\"" + var4 + "\"/>");
         } else {
            var1.b("  <x:Stylesheet HRef=\"" + this.g.o + "/stylesheet.css\"/>");
         }
      }

      this.h(var1);
      var1.b(" </x:ExcelWorkbook>");
      this.j(var1);
      var1.b("</xml><![endif]-->");
   }

   private void a(zafg var1, Worksheet var2, int var3) throws Exception {
      var1.b("   <x:ExcelWorksheet>");
      var1.b("    <x:Name>" + this.a(var2.getName()) + "</x:Name>");
      String var4 = (String)this.g.v.get("sheet" + zaff.a(var3, 3) + ".htm");
      if (var4 != null) {
         var1.b("    <x:WorksheetSource HRef=\"" + var4 + "\"/>");
      } else {
         var1.b("    <x:WorksheetSource HRef=\"" + this.g.o + "/sheet" + zaff.a(var3, 3) + ".htm\"/>");
      }

      var1.b("   </x:ExcelWorksheet>");
   }

   private void h(zafg var1) throws Exception {
      WorksheetCollection var2 = this.g.g.getWorksheets();
      var1.b("  <x:WindowHeight>" + zase.y(var2.n().getSettings().t()) + "</x:WindowHeight>");
      var1.b("  <x:WindowWidth>" + zase.y(var2.n().getSettings().s()) + "</x:WindowWidth>");
      var1.b("  <x:WindowTopX>" + zase.y(var2.n().getSettings().q()) + "</x:WindowTopX>");
      var1.b("  <x:WindowTopY>" + zase.y(var2.n().getSettings().r()) + "</x:WindowTopY>");
      var1.b("  <x:RefModeR1C1/>");
      var1.b("  <x:TabRatio>" + zase.y(var2.n().getSettings().getSheetTabBarWidth()) + "</x:TabRatio>");
      var1.b("  <x:ActiveSheet>" + zase.y(this.b) + "</x:ActiveSheet>");
      if (!var2.n().getSettings().isHScrollBarVisible()) {
         var1.b("  <x:HideHorizontalScrollBar/>");
      }

      if (!var2.n().getSettings().isVScrollBarVisible()) {
         var1.b("  <x:HideVerticalScrollBar/>");
      }

      if (!var2.n().getSettings().getShowTabs()) {
         var1.b("  <x:HideWorkbookTabs/>");
      }

   }

   private void i(zafg var1) throws Exception {
      var1.b("    <frameset rows=\"*,39\" border=0 width=0 frameborder=no framespacing=0>");
      String var2 = "sheet" + zaff.a(this.b + 1, 3) + ".htm";
      String var3 = (String)this.g.v.get(var2);
      if (var3 != null) {
         var1.b("     <frame src=\"" + var3 + "\" name=\"frSheet\">");
      } else {
         var1.b("     <frame src=\"" + this.g.o + "/" + var2 + "\" name=\"frSheet\">");
      }

      var1.b("     <frame src=\"" + (String)this.g.v.get("tabstrip.htm") + "\" name=\"frTabs\" marginwidth=0 marginheight=0>");
      var1.b("     <noframes>");
      var1.b("      <body>");
      var1.b("       <p>This page uses frames, but your browser doesn't support them.</p>");
      var1.b("      </body>");
      var1.b("     </noframes>");
      var1.b("    </frameset>");
   }

   private void j(zafg var1) throws Exception {
      Iterator var2 = this.a.getWorksheets().getNames().iterator();

      while(true) {
         Name var3;
         String var4;
         do {
            do {
               while(true) {
                  do {
                     if (!var2.hasNext()) {
                        return;
                     }

                     var3 = (Name)var2.next();
                  } while(var3.n() == 1);

                  if (com.aspose.cells.b.a.zv.a(var3.getText().toLowerCase(), "print_area", true) != 0 && com.aspose.cells.b.a.zv.a(var3.getText().toLowerCase(), "print_titles", true) != 0) {
                     var4 = var3.getRefersTo();
                     break;
                  }

                  this.a(var1, var3.getText(), var3.getSheetIndex(), var3.getRefersTo());
               }
            } while(var4 == null);
         } while(var4.length() <= 1);

         var4 = var4.substring(1);
         if (var4.indexOf("#REF!") != -1 || var4.equals("{}")) {
            var4 = "#REF!";
         }

         int var5 = -1;
         if (var3.getSheetIndex() != 0) {
            for(int var6 = 0; var6 < this.g.r.size(); ++var6) {
               Worksheet var7 = (Worksheet)this.g.r.get(var6);
               if (var3.getSheetIndex() - 1 == var7.m()) {
                  var5 = var6;
                  break;
               }
            }
         }

         var1.b(" <x:ExcelName>");
         var1.b("  <x:Name>" + this.a(var3.getText()) + "</x:Name>");
         if (var3.j()) {
            var1.b("  <x:Hidden/>");
         }

         if (var5 != -1) {
            var1.b("  <x:SheetIndex>" + var5 + "</x:SheetIndex>");
         }

         var1.b("  <x:Formula>" + this.a(var4) + "</x:Formula>");
         var1.b(" </x:ExcelName>");
      }
   }

   private void a(zafg var1, String var2, int var3, String var4) throws Exception {
      if (!"null".equals(var4) && !"".equals(var4) && null != var4) {
         var1.b(" <x:ExcelName>");
         var1.b("  <x:Name>" + var2 + "</x:Name>");
         var1.b("  <x:SheetIndex>" + var3 + "</x:SheetIndex>");
         var1.b("  <x:Formula>" + var4 + "</x:Formula>");
         var1.b(" </x:ExcelName>");
      }
   }

   private String a(String var1) {
      return com.aspose.cells.b.a.zv.a(var1, "&", "&amp;");
   }
}
